﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Text;

namespace TrafficApp
{
    public class Vector
    {
        public float X { get; set; }
        public float Y { get; set; }
        public int Xint
        {
            get { return (int)X; }
        }
        public int Yint
        {
            get { return (int)Y; }
        }
        public Vector()
        {
            X = 0;
            Y = 0;
        }
        public Vector(Point p)
        {
            X = p.X;
            Y = p.Y;
        }
        public Vector(float x, float y)
        {
            X = x;
            Y = y;
        }

        public float Length()
        {
            float x = X;
            float y = Y;
            double answer;
            x *= x;
            y *= y;
            answer = x + y;
            answer = Math.Sqrt(answer);
            return (float)answer;
        }

        public void Normalize()
        {
            float length = Length();
            X = X / length;
            Y = Y / length;
        }

        /// <summary>
        /// Converts this Applic.Vector to a human-readable string.
        /// </summary>
        /// <returns>A string that represents this Applic.Vector</returns>
        public override string ToString()
        {
            return "{X=" + Xint + ",Y=" + Yint + "}";
        }

        /// <summary>
        /// Override == operator
        /// </summary>
        public static bool operator ==(Vector a, Vector b)
        {
            // If both are null, or both are same instance, return true.
            if (System.Object.ReferenceEquals(a, b))
            {
                return true;
            }

            // If one is null, but not both, return false.
            if (((object)a == null) || ((object)b == null))
            {
                return false;
            }

            // Return true if the fields match:
            return a.X == b.X && a.Y == b.Y;
        }

        public static bool operator !=(Vector a, Vector b)
        {
            return !(a == b);
        }

        public void Multiply(float num)
        {
            X *= num;
            Y *= num;
        }

        //public int Direction()
        //{
        //    if (Y > 0)
        //    {
        //        return 3; // = south
        //    }
        //    else if (Y < 0)
        //    {
        //        return 1; // = north
        //    }
        //    else if (X > 0)
        //    {
        //        return 2; // = east
        //    }
        //    else if (X < 0)
        //    {
        //        return 4; // = west
        //    }
        //    return 0;
        //}
    }
}
